using System;

namespace Mono4Delphi
{
	
	public delegate void TDataSetNotifyEvent (ITDataset sender);
	public delegate void TFieldNotifyEvent (ITField sender);
	
	public interface ITField: ITComponent
	{
		bool AsBoolean {get; set;}
		int AsInteger {get; set;}
		long AsLargeInt {get; set;}
		string AsString {get; set;}
		double AsFloat {get; set;}
		bool IsNull {get;}
		void Clear();
		event TFieldNotifyEvent OnChange;
	}
	
	public interface ITDataset: ITComponent
	{
		void Open();
		void Close();		
		void Next();
		bool Eof{get; }
		ITField FieldByName(string aFieldName);
		event TDataSetNotifyEvent AfterInsert;
		event TDataSetNotifyEvent BeforePost;
		event TDataSetNotifyEvent OnCalcFields;
	}
	
	
	class MainClass
	{
		public static void Main (string[] args)
		{
			Console.WriteLine ("Hello World!");
		}
		
		public void InitPlugin(ITForm f)
		{
			ITDataset cds1 = (ITDataset)f.FindComponent("ClientDataSet1");
			cds1.OnCalcFields += HandleCds1OnCalcFields;
			
			col2 = cds1.FieldByName("COL2");
			col3 = cds1.FieldByName("COL3");
			colSum = cds1.FieldByName("COLSUM");
		}
		
		ITField colSum;
		ITField col2;
		ITField col3;
		
		void HandleCds1OnCalcFields (ITDataset sender)
		{
			//sender.FieldByName("COLSUM").AsInteger = sender.FieldByName("COL2").AsInteger + sender.FieldByName("COL3").AsInteger;
			colSum.AsInteger = col2.AsInteger + col3.AsInteger;
		}
		
	}
}

